package com.booksp.controller;

import com.booksp.pojo.Book;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/books")
public class BookController {
    @PostMapping
    public String save(Book book){
        System.out.println("book save ==> " + book);
        return "{module:'book save success'}";
    }

    @GetMapping
    public List<Book> selectAll(){
        List<Book> bookList = new ArrayList<Book>();

        Book book1 = new Book();
        book1.setType("计算机");
        book1.setName("SpringMVC");
        book1.setDescription("有点意思");
        bookList.add(book1);

        Book book2 = new Book();
        book2.setType("计算机");
        book2.setName("Spring Boot");
        book2.setDescription("有意思");
        bookList.add(book2);

        return bookList;
    }
}
